package com.glory.good_dark.utils;
import android.util.Log;

import com.glory.good_dark.application.App;
import com.glory.good_dark.entity.request.MessageFormat;
import com.glory.good_dark.entity.request.MessageHeader;
import com.glory.good_dark.entity.request.MessageReturn;
import com.glory.good_dark.entity.request.RequestMessage;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DateUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_NetUtils;

import org.apache.commons.lang3.StringEscapeUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author yi.zhang
 * @date 2019/6/10
 * @desc 网络请求类
 */
public class NetUtils {

    public static <T> void requestPostNet(String url, Object tag, FreeUI_EntityCallBack<T> callBack, String method, JsonObject jsonString) {
        MessageHeader header = new MessageHeader();
        header.setMACHINENAME(DeviceUtil.getPhoneModel());
        header.setMESSAGENAME(method);
        header.setTRANSACTIONID(UUID.randomUUID().toString());
        header.setWORKNO(App.userEntity.getWORKNO());
        header.setEVENTUSER(App.userEntity.getNAME());
        header.setEVENTTIME(FreeApi_DateUtils.getStringDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
        MessageReturn messageReturn = new MessageReturn();
        messageReturn.setRETURNCODE("");
        messageReturn.setRETURNMESSAGE("");
        MessageFormat format = new MessageFormat();
        format.setBody(jsonString);
        format.setHeader(header);
        format.setReturn(messageReturn);
        RequestMessage message = new RequestMessage();
        message.setMessage(format);
        Map<String, String> map = new HashMap<>();
        map.put("senderId","EAP2MESSender");
        map.put("requestMessage",StringEscapeUtils.unescapeJson(new Gson().toJson(message)));
        map.put("timeOut","30000");
        Log.e("requestDara", "requestDara: " + new Gson().toJson(message));
        FreeApi_LogUtils.saveErrorMessages("请求json",map.toString());
        FreeApi_NetUtils.requestPostNet(url, tag, map, callBack);

    }

}
